package com.huangyi.mstemplateservice.controller;

import com.huangyi.commondomain.domain.R;
import com.huangyi.commondomain.domain.ResultCode;
import com.huangyi.commondomain.exception.ServiceException;
import com.huangyi.mstemplateservice.userinfo.UserInfo;
import com.huangyi.mstemplateservice.userinfo.ValidationUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {
    // /test/info
    @GetMapping("/info")
    public void info() {
        log.info("接⼝调⽤测试");
    }

    @RequestMapping("/restResult")
    public R<UserInfo> test(int id) {
        if(id>0){
            UserInfo userInfo = new UserInfo();
            userInfo.setUsername("test");
            userInfo.setPassword("123456");
            return R.ok(userInfo);
        }
        return R.fail();
    }
    @GetMapping("/exception")
    public R<Void> exception() {
        throw new ServiceException(ResultCode.INVALID_CODE);
    }
    @PostMapping("/a")
    public int a1(@RequestBody @Validated ValidationUserDTO userDto) {
        System.out.println(userDto);
        return 0;
    }
    @PostMapping("/post")
    public void post(ValidationUserDTO validationUserDTO) {
        System.out.println(validationUserDTO);
    }
    @GetMapping("/{name}/{id}")
    public void testPathVariable(@PathVariable("name") String name, @PathVariable("id") int id) {
        System.out.println("name" + name);
        System.out.println("id" + id);
    }
}
